#include "GameScene.h"
#include "Field.h"
#include "Director.h"

GameScene::GameScene(int a)
	:_field(0)
{
	this->reset(a);
}

void GameScene::reset(int a)
{
	if( _field )
	{
		delete _field;
	}
	_field = new Field();
	_field->init(10,10, a);

	_endTime = 0.f;
	_endFlag = false;
}


GameScene::~GameScene(void)
{
	delete _field;
}

void GameScene::Update()
{
	_field->display();


	if( !_endFlag )
	{
		short result = _field->checkResult();
		
		if( result == 0 ) _field->update();
		else
		{
			_endFlag = true;

			if( result == 1) _endTitle.setTextureName(".//image/success.png");
			else if(result == -1) _endTitle.setTextureName(".//image/failed.png");
			_endTitle.setImageSize(Vector3l(600,200));
			_endTitle.setPosition(Vector3f(600.f,340.f));
		}
	}
	else
	{
		_endTime += 0.01f;
		_endTitle.draw();
		
		if( _endTime >= 2.0f)
			SharedDirector()->GetSceneManager()->SelectScene("TitleScene");
	}
}
